// import http from "../../../class/Utils/Http"
// import user from "../../../class/Utils/User"
import tips from "../../../class/Utils/Tips"

var app = getApp();
Page({
  data: {
    mobanstyle:1,
    sc_num:0,
    aa: 0,
    sctig: 0,//靠谱状态 1 靠谱+1
    kpshu: 121, //靠谱状态数,
    piclist: ['https://toocle.y.netsun.com/Uploads/mingpian_pic/5b97b690138c0.jpg','https://toocle.y.netsun.com/Uploads/mingpian_pic/5be4f82de4b22.jpg'],
    bofang: 0,
    bb: 0,
    yuyinqianmingtig: 0,
    openinfo: false,
    mykehulist: [
      { pic: 'https://toocle.y.netsun.com/Uploads/head/5bdbe3d11a6d7.png', id: '1' },
      { pic: 'https://toocle.y.netsun.com/Uploads/head/5bdbe3d11a6d7.png', id: '2' },
      { pic: 'https://toocle.y.netsun.com/Uploads/head/5bdbe3d11a6d7.png', id: '3' },
      { pic: 'https://toocle.y.netsun.com/Uploads/head/5bdbe3d11a6d7.png', id: '4' },
      { pic: 'https://toocle.y.netsun.com/Uploads/head/5bdbe3d11a6d7.png', id: '5' },
      ],
    xiaoxi_count: 1,
    info: { pic: 'https://toocle.y.netsun.com/Uploads/head/5bdbe3d11a6d7.png', dizhi: '辽宁省沈阳市和平区青年大街 322号昌鑫大厦 F 座14层', xingming: '郭峰', zhiwei: '前端设计师', shouji: '13940563477', youxiang: 'guofeng@netsun.com', gongsi: '浙江网盛生意宝股份有限公司', guhua: '02483959249', weixin: 'elicef', qianming:'这是文字的个性签名，就在这里显示了。'},
    renqi:'666',
    tjprolist:[
      { id: '1', title: '测试产品一号测试产品一号测试产品一号测试产品一号', xtitle: '这是一款中规中矩的测试产品请注意查看购买这是一款中规中矩的测试产品请注意查看购买', xprice: '500.00', yprice: '800.00', pic: 'http://img5.imgtn.bdimg.com/it/u=1723581993,3162193044&fm=26&gp=0.jpg', },
      { id: '2', title: '测试产品二号', xtitle: '这是一款中规中矩的测试产品请注意查看购买', xprice: '500.00', yprice: '800.00', pic: 'http://img3.imgtn.bdimg.com/it/u=2362821575,1362847906&fm=26&gp=0.jpg', },
      { id: '3', title: '测试产品三号', xtitle: '这是一款中规中矩的测试产品请注意查看购买', xprice: '500.00', yprice: '800.00', pic: 'http://img4.imgtn.bdimg.com/it/u=292177107,2470385035&fm=26&gp=0.jpg', },
    ],
  },
  onLoad: function (get) {
    var that = this
    var user = wx.getStorageSync('user');
    that.setData({
      qyid: get.qyid || 1
    })

  },
  onShow: function () {
    var that = this
    var user = wx.getStorageSync('user');
    wx.removeStorageSync('pic_post_data')

    //console.log(user)
    if (!user) {
      that.setData({
        shouquan: 1
      })
    } else {

      that.setData({
        shouquan: 0
      })
      

      that.infomingpian()
      //  that.toocle_car();
      that.stopmuqianming()

    }

    

    wx.onBackgroundAudioStop(function () {
      console.log('onBackgroundAudioStop')
      that.setData({
        bofang: '0',
        yuyinqianmingtig: 0,
      })
    })


  },
  //下拉刷新
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading()
    tips.loading("更新信息...")
    var that = this;
    var user = wx.getStorageSync('user');
    var userid = user.userid

    
  


    wx.stopPullDownRefresh()
    wx.hideNavigationBarLoading()
    setTimeout(function () {
      wx.hideLoading()
    }, 1000)


  },
  //图片展示查看图片
  previewImageduo: function (e) {
    var that = this
    var current = e.currentTarget.dataset.src;
    wx.previewImage({
      current: current,// 当前显示图片的http链接
      urls: that.data.piclist // 需要预览的图片http链接列表
    })
  },
  //添加到通讯录
  adddianhuabu: function () {
    var that = this
    wx.addPhoneContact({
      //lastName: that.data.lastName,
      photoFilePath: that.data.info.pic,//头像
      firstName: that.data.info.xingming,//联系人姓名
      organization: that.data.info.gongsi,//公司名称
      title: that.data.info.zhiwei,//公司职位
      mobilePhoneNumber: that.data.info.shouji,//联系人手机号
      weChatNumber: that.data.info.weixin,//微信号
      email: that.data.info.youxiang,//电子邮箱
      workAddressCity: that.data.info.dizhi,//工作城市
      workPhoneNumber: that.data.info.guhua,//办公电话
    })
  },
  //播放语音个人签名
  playyuyinqianming: function () {
    var that = this
    var yyqmtig = that.data.bofang
    console.log(yyqmtig)
    if (yyqmtig == 0) {
      wx.playBackgroundAudio({
        dataUrl: that.data.info.qianmingmp3,
        title: '个性签名',
      })
      that.setData({
        bofang: 1,
        yuyinqianmingtig: 1,
      })

    }
    if (yyqmtig == 1) {
      wx.stopBackgroundAudio()
      that.setData({
        bofang: '0',
        yuyinqianmingtig: 0,
      })
      console.log(yyqmtig)
    }


  },
  //跳转页面 停止播放
  onHide: function () {
    var that = this
    wx.stopBackgroundAudio()
    that.setData({
      bofang: '0',
    })
  },
  //自动停止播放语音签名
  stopmuqianming: function () {
    var that = this
    wx.onBackgroundAudioStop(function () {
      that.setData({
        yuyinqianmingtig: 0
      })
    })
  },
  //播放语音签名
  playyuyinqianmingb: function () {
    var that = this
    wx.playBackgroundAudio({
      dataUrl: that.data.yuyinqianming,
      title: '个性签名',

      success: function () {
        wx.getBackgroundAudioPlayerState({
          success: function (res) {
            var status = res.status
            if (status == 1) {
              wx.stopBackgroundAudio()
              that.setData({
                bofang: '0',
              })
            }
          }
        })
      }

    })
  },
  //点击加减靠谱
  aabb: function () {
    var that = this
    var user = wx.getStorageSync('user');
    var sc_num = that.data.sc_num
    var stig = that.data.sctig//1是靠谱 0是没选
    var kptig = that.data.kpshu//靠谱当前的数
    var aatig = that.data.aa// 1是运行红心动画 0是隐藏红心动画
    if (stig == 0) {
      that.setData({
        aa: 1,
        sctig: 1,
        jia1: '+1',
        kpshu: kptig + 1,
        sc_num: parseInt(sc_num) + 1

      })
      setTimeout(function () {
        that.setData({
          aa: 0,
        })
      }, 1000)
      http.req("/Mingpian/mp_sc", { userid: user.userid, id: that.data.info.id, title: that.data.info.xingming })
    } else {
      that.setData({
        aa: 1,
        sctig: 0,
        jia1: '-1',
        kpshu: kptig - 1,
        sc_num: parseInt(sc_num) - 1
      })
      setTimeout(function () {
        that.setData({
          aa: 0,
        })
      }, 1000)
      http.req("/Mingpian/del_mp_sc", { userid: user.userid, id: that.data.info.id })
    }

  },
  onShareAppMessage: function () {
    var that = this
    return {
      title: '我是' + that.data.info.gongsi + "的" + that.data.info.xingming,
      path: '/pages/mingpian/card/card?id=' + that.data.info.id,
      imageUrl: that.data.info.pic,

      success: function (res) {
        http.req("/Mingpian/fenxiang", { id: that.data.info.id }, function (res) {

          tips.ok("转发成功")

        })
      },
    }

  },
  bindGetUserInfo: function (e) {
    var that = this
    user.user(this, function () {
      that.setData({
        shouquan: 0
      })
      
      that.infomingpian()
    })
  },
  //改变名片展开信息
  changempinfo: function () {
    var that = this
    that.setData({
      openinfo: !that.data.openinfo
    })
  },
  //去首页
  gotohome: function () {
    wx.switchTab({
      url: '/pages/index/index'
    })
  },
  //去我的
  gotomain: function () {
    wx.switchTab({
      url: '/pages/main/menu/menu'
    })
  },
  //去名片
  gotowodemingpian: function (e) {
    wx.redirectTo({
      url: '/pages/mingpian/card/card?id=' + this.data.info.id
    })
  },
  //去旺铺
  gotowangpu: function () {
    var that = this
    var info = this.data.info
    if (info.wx_user.toocle_cid == 0) {
      tips.error("暂无旺铺")
      return false
    }
    // if(info.wx_user.toocle_cid==100387){
    //     tips.redirectTo('/pages/mingpian/wangpu/index/index?mid='+this.data.info.id);
    // }else{
    tips.redirectTo("/pages/toocle/shop/index/index?cid=" + info.wx_user.toocle_cid + "&time=" + info.wx_user.toocle_ctime + "&quanmenuid=1&mid=" + that.data.info.id + "&menus=2&userid=" + info.wx_user.id);
    // }

  },
  //去企业介绍
  gotojieshao: function () {
    var info = this.data.info
    if (info.wx_user.toocle_cid == 0) {
      tips.error("暂无旺铺")
      return false
    }

    tips.redirectTo("/pages/toocle/shop/index/index?cid=" + info.wx_user.toocle_cid + "&time=" + info.wx_user.toocle_ctime + "&quanmenuid=3&userid=" + info.wx_user.id);

  },
  //去生意宝服务中心123123
  // gotofuwuzhongxin:function(){
  //     tips.redirectTo('/pages/mingpian/tooclefuwu/tooclefuwu');
  // },
  //去生意宝服务中心
  gotofuwuzhongxin: function () {
    tips.godaohang('/pages/main/menu/menu');
  },
  //拨打手机
  callshouji: function () {
    var that = this

    if (that.data.info.shouji !== '') {
      wx.makePhoneCall({
        phoneNumber: that.data.info.shouji,
        success: function () {
          console.log("成功拨打电话")
        }
      })
    }


  },
  //拨打固话
  callguhua: function () {
    var that = this
    if (that.data.info.guhua !== '') {
      wx.makePhoneCall({
        phoneNumber: that.data.info.guhua,
        success: function () {
          console.log("成功拨打电话")
        }
      })
    }

  },
  //复制微信号
  copyweixin: function (e) {
    var that = this;
    var thatweixinhao = that.data.info.weixin
    console.log(thatweixinhao)
    if (thatweixinhao == '' || thatweixinhao == 'undefined' || thatweixinhao == 'unll') {
    } else {
      wx.setClipboardData({
        data: that.data.info.weixin,
        success: function (res) {
          //console.log("success" + res.data)
        },
        
      });
    }
  },
  //复制邮箱
  copyyouxiang: function (e) {
    var that = this;
    var thatyouxiang = that.data.info.youxiang
    console.log(thatyouxiang)
      wx.setClipboardData({
        data: thatyouxiang,
        success: function (res) {
          //console.log("success" + res.data)
        },

      });
  },
  //复制名片内容
  copyinfo: function (e) {
    var that = this;
    var thattext = e.currentTarget.dataset.text
    console.log(thattext)
    wx.setClipboardData({
      data: thattext,
      success: function (res) {
        //console.log("success" + res.data)
      },
    });
  },
  //编辑名片
  selectaddfangshi: function () {
    var that = this
    wx.showModal({
      //title: "温馨提示",
      content: '选择编辑方式',
      cancelText: "手动编辑",//默认是“取消”
      confirmText: "拍摄名片",//默认是“确定”
      // confirmColor: '#586fbd',//确定文字的颜色
      success: function (res) {
        if (res.cancel) {
          //点击取消,默认隐藏弹框
          tips.goto('/pages/mingpian/add/add')
        } else {
          that.upimg()

        }
      },
    })
  },
  //牛逼的扫描名片功能 嘿嘿嘿
  upimg: function () {
    var that = this;

    wx.chooseImage({
      count: 1,
      success: function (res) {
        tips.loading("图片处理中..")
        //console.log(res)
        const tempFilePaths = res.tempFilePaths
        wx.uploadFile({
          url: app.httpurl.url + '/Api/mingpianshibie',
          filePath: tempFilePaths[0],
          name: 'pic',
          success: function (result) {
            const res = JSON.parse(result.data)
            console.log(res)
            if (res.code === "0") {
              var post_data = {}
              if (res.data.organization) {
                post_data.gongsi = res.data.organization['0'].item.name
              }
              if (res.data.formatted_name) {
                post_data.xingming = res.data.formatted_name['0'].item
              }
              if (res.data.label) {
                post_data.dizhi = res.data.label['0'].item.address
              }
              if (res.data.title) {
                post_data.zhiwei = res.data.title['0'].item
              }
              if (res.data.telephone) {
                post_data.shouji = res.data.telephone['0'].item.number
              }
              if (res.data.telephone.length > 1) {
                post_data.guhua = res.data.telephone['1'].item.number
              }
              if (res.data.email) {
                post_data.youxiang = res.data.email['0'].item
              }
              console.log(post_data)
              wx.setStorageSync('pic_post_data', post_data)
              tips.goto("/pages/mingpian/add/add?pic_post_data=1")
            } else {
              // tips.error("识别识别，请保证名片清晰!")

              wx.showModal({
                // title: "温馨提示",
                content: '识别失败，请保证名片拍摄清晰哦!',
                cancelText: "我知道了",//默认是“取消”
                confirmText: "重新拍摄",//默认是“确定”
                // confirmColor: '#586fbd',//确定文字的颜色
                success: function (res) {
                  if (res.cancel) {
                    //点击取消,默认隐藏弹框
                  } else {
                    that.upimg()

                  }
                }
              })
              tips.loaded()





            }

          }
        })
      }
    })
  },
  //点击单个图片 单独放大
  previewImage: function (e) {
    console.log(e)
    var that = this;
    var current = e.currentTarget.dataset.src;
    wx.previewImage({
      current: current, // 当前显示图片的http链接
      urls: [current] // 需要预览的图片http链接列表
    })
  },

})